package com.open.party.cloud.view.home.jiCengDangJian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.open.party.cloud.R;
import com.open.party.cloud.model.ZyzJiFenBean;
import com.sinothk.android.utils.XUtils;
import com.sinothk.view.image.rounded.RoundedImageView;

import java.util.ArrayList;
import java.util.List;

import com.sinothk.android.utils.inters.OnSuperListener;

public class ZyzJiFenListAdapter extends RecyclerView.Adapter<ZyzJiFenListAdapter.ViewHolder> {

    // 展示数据
    private ArrayList<ZyzJiFenBean> mData;
    private Context mContext;
    private OnSuperListener<ZyzJiFenBean> onItemClickListener;

    public ZyzJiFenListAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

    public void setOnSuperListener(OnSuperListener<ZyzJiFenBean> onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setData(List<ZyzJiFenBean> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<ZyzJiFenBean> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public ZyzJiFenListAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.zyz_ji_fen_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ZyzJiFenListAdapter.ViewHolder holder, final int position) {
        // 绑定数据
        final ZyzJiFenBean itemData = mData.get(position);

        holder.numTv.setText("" + (position + 4));
        holder.nameTv.setText(XUtils.string().getNotNullValue(itemData.getUserName()));
        holder.scoreTv.setText("" + itemData.getScore());

        Glide.with(mContext).load(itemData.getPhoto()).placeholder(R.drawable.icon_default_img).into(holder.imageView);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout rootView;
        TextView numTv, nameTv, scoreTv;
        RoundedImageView imageView;

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);

            imageView = itemView.findViewById(R.id.imageView);

            numTv = itemView.findViewById(R.id.numTv);
            nameTv = itemView.findViewById(R.id.nameTv);
            scoreTv = itemView.findViewById(R.id.scoreTv);
        }
    }
}